home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Unable to check calloc`s
- Date: Tue, 06 Feb 96 15:23:18 GMT
- Organization: none
- Message-ID: <823620198snz@genesis.demon.co.uk>
- References: <4f2l8a$c98@gail.ripco.com>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4f2l8a$c98@gail.ripco.com> mambuhl@ripco.com "Martin Ambuhl" writes:
-
- ...
-
- >5) Hard coding constant values is usually a mistake:
- > #include <stdlib.h>
- > #define ARRAYSIZE 9
- > {
- > float **x;
- > if (x = malloc(ARRAYSIZE*sizeof(float *))) == 0)
- ^
- You need another ( here
-
- > exit(EXIT_FAILURE);
- > }
-
- And that is usually better written as:
-
- #include <stdlib.h>
- #define ARRAYSIZE 9
- {
- float **x;
- if (x = malloc(ARRAYSIZE*sizeof(*x))) == 0)
- exit(EXIT_FAILURE);
- }
-
- or possibly:
-
- #include <stdlib.h>
- #define ARRAYSIZE 9
- {
- float **x = malloc(ARRAYSIZE*sizeof(*x));
- if (x == NULL)
- exit(EXIT_FAILURE);
- }
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-